{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fc0a5372",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "## 关于麦克风包安装\n",
    "## 优化ASR(自动语音识别)机器人\n",
    "## 连接图灵机器人(不用自己的字典)\n",
    "## 语音合成\n",
    "# 关于麦克风包安装\n",
    "* 安装 speech_recognition\n",
    "> pip install SpeechRecognition\n",
    "* 安装 PyAudio\n",
    "> Not found name \\\"PyAudio\\\" moudle\n",
    "> pip install pipwin\n",
    "> pipwin install PyAudio\n",
    "# 优化ASR(自动语音识别)机器人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2011dc3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#  百度密钥\n",
    "API_KEY = 'nSECRET_KEY = '"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0973143a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9438b4f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "xu_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "xu_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f45c663",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "667f2fbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "asr_output = eval(asr(xu_token,'1.wav'))['result'][0]\n",
    "asr_output"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7b2d8c2",
   "metadata": {},
   "source": [
    "# 连接图灵机器人\n",
    "* API V2.0是基于图灵机器人平台语义理解、深度学习等核心技术，为广大开发者和企业提供的在线服务和开发接口。\n",
    "* 接口地址：\n",
    "> http://openapi.turingapi.com/openapi/api/v2\n",
    "* 请求方式:\n",
    "> POST\n",
    "* 请求参数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fdce1a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
